package com.redteam.data.beans;

import com.redteam.data.enums.AircraftType;
import com.redteam.data.enums.ItemType;
import java.io.Serializable;
import java.text.DecimalFormat;

/**
 * A java bean for Rental Items
 * @author Teddy Karam
 */
public class RentalItem implements Serializable {

    private long id;
    private double rate;
    private ItemType itemType;
    private long fboID;
    private AircraftType aircraftType;
    private static final long serialVersionUID = 1L;

    /**
     * RentalItem full constructor
     * @param id
     * @param fboID
     * @param rate
     * @param itemType
     * @param aircraftType
     */
    public RentalItem(long id, long fboID, double rate, String itemType, String aircraftType) {
        this.setId(id);
        this.setRate(rate);
        this.setType(itemType);
        this.setFboID(fboID);
        this.setAircraftType(aircraftType);
    }

    /**
     * Default bean constructor
     */
    public RentalItem() {
    }

    /**
     * Returns the FBO id of the current rental item
     * @return fboID
     */
    public final long getFboID() {
        return fboID;
    }

    /**
     * Sets the FBO id of the current rental item
     * @param fboID
     */
    public final void setFboID(long fboID) {
        this.fboID = fboID;
    }

    /**
     * Returns the id in the database associated with the current rental item
     * @return id
     */
    public final long getId() {
        return id;
    }

    /**
     * Sets the rental item id according to the id in the database
     * @param id
     */
    public final void setId(long id) {
        this.id = id;
    }

    /**
     * Returns the rental rate for the current rental item
     * @return rate
     */
    public final double getRate() {
        return rate;

    }

    /**
     * set or update the rate for the current rental item
     * @param rate
     */
    public final void setRate(double rate) {
        DecimalFormat twoDForm = new DecimalFormat("#.##");
        this.rate = Double.valueOf(twoDForm.format(rate));
    }

    /**
     *Returns the rental type associated with the current rental item as a string
     * @return itemType
     */
    public final String getType() {
        return itemType.getDescription();

    }

    /**
     * Sets the type of the current item simulator or airplane
     * @param type
     */
    public final void setType(String type) {
        this.itemType = ItemType.valueOf(type);
    }

    /**
     * Returns the aircraft type
     * @return aircraftType
     */
    public AircraftType getAircraftType() {
        return aircraftType;
    }

    /**
     * Sets the type of the aircraft
     * @param aircraftType
     */
    public final void setAircraftType(String aircraftType) {
        this.aircraftType = AircraftType.valueOf(aircraftType);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final RentalItem other = (RentalItem) obj;
        if (this.id != other.id) {
            return false;
        }
        if (Double.doubleToLongBits(this.rate) != Double.doubleToLongBits(other.rate)) {
            return false;
        }
        if (this.itemType != other.itemType) {
            return false;
        }
        if (this.fboID != other.fboID) {
            return false;
        }
        if (this.aircraftType != other.aircraftType) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 71 * hash + (int) (this.id ^ (this.id >>> 32));
        hash = 71 * hash + (int) (Double.doubleToLongBits(this.rate) ^ (Double.doubleToLongBits(this.rate) >>> 32));
        hash = 71 * hash + (this.itemType != null ? this.itemType.hashCode() : 0);
        hash = 71 * hash + (int) (this.fboID ^ (this.fboID >>> 32));
        hash = 71 * hash + (this.aircraftType != null ? this.aircraftType.hashCode() : 0);
        return hash;
    }
}
